package com.wealth.scsj.b_app.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.bean.LeftBean;
import com.wealth.scsj.b_app.bean.SelectAppClass1Bean;
import com.wealth.scsj.b_app.event.FirstEvent;
import com.wealth.scsj.b_app.utils.RxBus;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品管理左侧列表
 */

public class LeftAdapter extends BaseQuickAdapter<SelectAppClass1Bean.DataBean,BaseViewHolder> {

    private List<Boolean> isClicks;
    public int currentPosition = 0;

    public LeftAdapter(List data) {
        super(R.layout.item_left_layout,data);
        isClicks = new ArrayList<>();
    }

    @Override
    protected void convert(final BaseViewHolder helper, SelectAppClass1Bean.DataBean item) {

        helper.setText(R.id.title_tv,item.getName());
        helper.setText(R.id.content_tv,"("+item.getGoodsNumber()+"种商品)");
        LinearLayout item_left_ll = (LinearLayout) helper.getView(R.id.item_left_ll);

        if(helper.getLayoutPosition() == currentPosition){
            item_left_ll.setBackgroundResource(R.drawable.bg_classify);
            RxBus.getDefault().post(new FirstEvent("LeftAdapter",item.getId()));
        }else {
            item_left_ll.setBackgroundResource(R.color.mybackcolor);
        }

        item_left_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                currentPosition = helper.getLayoutPosition();
                notifyDataSetChanged();
            }
        });

    }
}
